<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
		<div class="btn-group tool-button" style="padding:8px 0">
			<table>
           		<tbody>
           			<tr>
                  		<td>
                       		<input type="text" id="nameStr" name="nameStr" onclick="this.value=''" class="form-control" placeholder="名称" autofocus>
                        </td>
                         <td style="padding-left: 5px;">
                            <button id="searchBtn" type="button" class="btn btn-default"><i class="fa fa-search"></i>&nbsp;查询</button>
                      	</td>
                        </tr>
                    </tbody>
            </table>
		</div>
	</header>
	<div class="panel-body" style="padding-top: 70px;">
		<div class="box">
			<div class="box-body">
				<div class="col-sm-12">
					<div class="row">
				        <table class="table table-bordered table-hover mg-t datatable">
				            <thead>
				            <tr>
								<th>学员姓名</th>
								<th>电话</th>
								<th>所属主体</th>
								<th>学习进度</th>
								<th>状态</th>
								<th>操作</th>
			    		</table>
	    			</div>
				</div>
			</div>
		</div>
	</div>
<script language="JavaScript">
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">frtip',
            "searching": false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/plugins/datatables/cn.json"
            },
            "preDrawCallback": function () {
                sublime.showLoadingbar($(".main-content"));
            },
            "drawCallback": function () {
                sublime.closeLoadingbar($(".main-content"));
            },
            "ajax": {
                "url": "${base}/platform/student/toSubjectOneData",
                "type": "post",
                "data": function (d) {
                	d.name=$('#nameStr').val();
                }
            },
            "order": [[0, "desc"]],
            "columns": [
				{"data": "name", "bSortable": true},
				{"data": "mobile", "bSortable": true},
				{"data": "company_id", "bSortable": true},
				{"data": "progress", "bSortable": true},
				{"data": "state", "bSortable": true}
            ],
            "columnDefs": [
               	{
                 	"render": function (data, type, row) {
                   		return getCompany(data);
             		 },
                  	"targets": 2
               	},
               	{
               		"render": function (data, type, row) {
                    	if(data==0){
                        	return "入学";
                    	}else if(data==1){
                    		return "理论培训";
                    	}else if(data==2){
                    		return "操作培训";
                    	}else if(data==9){
                    		return "完成";
                    	}
                    },
                    "targets": 3
               	},
               	{
               		"render": function (data, type, row) {
                    	if(data==0){
                        	return "正常";
                    	}else if(data==1){
                    		return "失效";
                    	}else if(data==2){
                    		return "过期";
                    	}
                    },
                    "targets": 4
               	},
                {
                    "render": function (data, type, row) {
                    	 return '<div>'
						 + '<a class="btn btn-xs btn btn-default " href="${base}/platform/student/toSubjectOneEdit/' + row.id + '"><i class="fa fa-edit"></i>&nbsp;修改</a> '
						 + '</div>';
                    },
                    "targets": 5
                }
            ]
        });
        $("#searchBtn").on('click', function () {
            datatable.ajax.reload();
        });
    }
    $(function () {
        initDatatable();
    });
    
    function getCompany(id){
    	var datas="";
    	$.ajax({
			url : "${base}/platform/student/getCompany",
			data : {
				id : id
			},
			type : "post",
			async : false,
			dataType : "json",
			success : function(data){
				datas= data;
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				return false;
			}
		});
    	return datas;
    }
</script>

<%}%>
